package LinkList;

public class MyQueue {
    private int[] elem;
    private int front;
    private int rear;


    public MyQueue(int k){
        this.elem = new int[k + 1];
    }

   //入队
    public boolean enQueue(int value){
        if(isFull()){
            return false;
        }
        this.elem[rear] = value;
        rear = (rear + 1)% this.elem.length;
        return true;
    }

   //出队
    public boolean deQueue(){
        if(isEmpty()){
            return false;
        }
        front  = (front + 1)% this.elem.length;
        return true;

    }

    public int Front(){
        if(isEmpty()){
            return -1;
        }
        int Front = this.elem[front];
        return this.elem[front];

    }

    //得到队尾元素
    public int Rear(){
      if(isEmpty()){
          return -1;
      }
      int index = (rear == 0) ? this.elem.length - 1 : rear - 1;
      return this.elem[index];
    }

    public boolean isEmpty(){
        if(rear == front){
            return true;
        }
        return false;

    }

    public boolean isFull(){
        if((rear +1)% this.elem.length == front){
            return true;
        }
        return false;
    }


}
